﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Business_Layer;

public partial class ProductDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
      
        
        if (!IsPostBack)
        {
            this.Display();
   
        }
    }

    private void Display()
    {
        string ProductID = Request["ProductID"];
        DataTable Product = Product_BUS.getProductsByProdID(int.Parse(ProductID));


        //String sqlProduct = "SELECT p.*, c.CategoryName FROM Products p, Categories c WHERE p.CategoryID=c.CategoryID AND ProductID=@ProductID";
        //DataTable Product = Database.GetData(sqlProduct, "@ProductID", ProductID);

        //lblCategory.Text = Product.Rows[0]["CatName"].ToString();
        //lblDescription.Text = Product.Rows[0]["Decription"].ToString();
        //lblDescription.Visible = true;
        lblProductID.Text = Product.Rows[0]["ID"].ToString();
        lblProductName.Text = Product.Rows[0]["Name"].ToString();
        int sl = int.Parse(Product.Rows[0]["Total"].ToString());
        lblUnitPrice.Text = String.Format("{0:0,0 VNĐ}", Product.Rows[0]["Price"] );
        imgImage.ImageUrl = "images/SanPham/" + Product.Rows[0]["Image"];
        Label7.Text = Product.Rows[0]["TenTacGia"].ToString();
        Label8.Text = Product.Rows[0]["tennxb"].ToString();
        Label9.Text = Product.Rows[0]["chieurong"].ToString() + "x" + Product.Rows[0]["chieudai"].ToString()+ "cm";
        Label10.Text = "( "+Product.Rows[0]["giamgia"].ToString()+ "% )";
        Label11.Text = Product.Rows[0]["rank"].ToString();
        ImageButton2.CommandArgument = ProductID;
        ShoppingCart Cart = (ShoppingCart)Session["ShoppingCart"];
        try
        {
            sl = sl - int.Parse(Cart.Rows[0][3].ToString());
        }
        catch
        { }
        for (int i = 1; i <= sl; i++)
            DropDownList1.Items.Add(i.ToString());
        DropDownList1.Width = 50;
        DropDownList1.SelectedIndex = 0;
    }

    protected void btnAddToCart_Click(object sender, EventArgs e)
    {
    
    }
    
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        ShoppingCart Cart = (ShoppingCart)Session["ShoppingCart"];

        ImageButton btn = (ImageButton)sender;
        int ProductID = int.Parse(btn.CommandArgument);
        int Quantity = int.Parse(DropDownList1.SelectedItem.Text);

        Cart.Add(ProductID, Quantity);

        ASP.masterpage_master master = (ASP.masterpage_master)this.Master;
        master.RefreshShoppingCartInfo();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
